package com.assistant.tools;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class PictureFileMgr {
	
	public static boolean createFolder(String folderPath)
	{
		File folder=new File(folderPath);
		if(!folder.exists())
			return folder.mkdirs();
		return true;
	}
	public static boolean deleteFolder(String folderPath){
		File folder=new File(folderPath);
		if(folder.exists()){
			return folder.delete();
		}
		return false;
	}
	
	public static void saveFile(Bitmap bm,String folderPath, String fileName) throws IOException {    
		File dirFile = new File(folderPath);    
	    if(!dirFile.exists()){    
	         dirFile.mkdir();    
		 }    
		 File myCaptureFile = new File(folderPath + fileName);  
		 if(!myCaptureFile.exists())
			 myCaptureFile.createNewFile();
		 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));    
		 bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);    
		 bos.flush();    
		 bos.close();    
	}
	
	public static Bitmap getFile(String filepath){
		File f=new File(filepath);
		if(f.exists())
		{
			return BitmapFactory.decodeFile(filepath);
		}
		return null;
	}
	
	public static boolean delete(String filename){
		File f=new File(filename);
		if(f.exists())
			return f.delete();
		return false;
	}
	public static String[] getAllFilesNames(String folder)
	{
		File folderFile=new File(folder);
		if(folderFile.exists()){
			return folderFile.list();
		}
		return null;
	}
	

}
